import { UIBase } from "../framework/UIBase";
import ButtonExGroup from "../component/ButtonExGroup";

const {ccclass, property} = cc._decorator;

@ccclass
export default class MainView extends UIBase {

    @property([cc.Node])
    pageGroup: cc.Node[] = [];

    @property(ButtonExGroup)
    btnExGroup: ButtonExGroup = null;

    private pageIndex = -1;
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        if (this.btnExGroup) {
            this.btnExGroup.node.on("ButtonExGroup",this.btnExGroupClick,this);
        }
    }

    start () {

    }

    btnExGroupClick (event) {
        if (event) {
           this.showPage(event.index);
        }
    }

    showPage (index) {
        if (this.pageIndex == index) {
            return
        }
        
        if (this.pageIndex == -1) {
            this.pageGroup[index].active = true;
        }else {
            this.pageGroup[this.pageIndex].active = false;
            this.pageGroup[index].active = true;
        }
        this.pageIndex = index;
    }

    onShow() {
        this.showPage(0);
    }

    onHide() {
    }
}
